package com.czy.owner.adapter;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Display;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.ChainStoresModel;
import com.czy.owner.entity.OnLineOrderServiceModel;
import com.czy.owner.utils.StringUtils;
import com.easyrecycleview.adapter.BaseViewHolder;

import java.util.List;


/**
 * Created by wangyang
 */
public class StoreSelectAdapter extends BaseRecyclerAdapter<ChainStoresModel, StoreSelectAdapter.StoreSelectAdapterHolder> {
    private Context ctx;
    private boolean isLocSuccess;
    private int storeId;

    public StoreSelectAdapter(Context context, List<ChainStoresModel> data) {
        super(context, data);
        this.ctx = context;
    }

    public void setStoreId(int storeId) {
        this.storeId = storeId;
    }

    public boolean isLocSuccess() {
        return isLocSuccess;
    }

    public void setLocSuccess(boolean locSuccess) {
        isLocSuccess = locSuccess;
    }

    @Override
    public void onBindViewHolder(StoreSelectAdapterHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.bindData(data.get(position));

    }

    @Override
    public StoreSelectAdapterHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new StoreSelectAdapterHolder(layoutInflater.inflate(R.layout.item_select_bespoke_store, parent, false));
    }

    public class StoreSelectAdapterHolder extends BaseRecyclerAdapter.ViewHolder {
        private TextView tv_store_name, tv_store_distance;

        public StoreSelectAdapterHolder(View itemView) {
            super(itemView);
            tv_store_name = (TextView) itemView.findViewById(R.id.tv_store_name);
            tv_store_distance = (TextView) itemView.findViewById(R.id.tv_store_distance);

        }

        public void bindData(ChainStoresModel model) {
            if (storeId == model.getStoreId()) {
                tv_store_name.setTextColor(ctx.getResources().getColor(R.color.appThemeColor));
                tv_store_distance.setTextColor(ctx.getResources().getColor(R.color.appThemeColor));
            } else {
                tv_store_name.setTextColor(ctx.getResources().getColor(R.color.text_bespke));
                tv_store_distance.setTextColor(ctx.getResources().getColor(R.color.text_bespke));

            }
            tv_store_name.setText(model.getStoreName());
            if (isLocSuccess && !StringUtils.isEmpty(model.getMin())) {
                tv_store_distance.setText(model.getMin() + "km");
                tv_store_distance.setVisibility(View.VISIBLE);
            } else {
                tv_store_distance.setVisibility(View.GONE);
            }
        }
    }


}
